/******************************************************************************
 *                  Shanghai ChipON Micro-Electronic Co.,Ltd
 ******************************************************************************
 *  @File Name        : kf8a100fxx_eeprom.h
 *  @Author           : ChipON AE/FAE Group
 *  @Date             : 2023-12-19
 *  @HW Version       : KF8A100Fxx
 *  @Lib Version      : V2.0.1
 *  @Description      : This file provides the driver for the eeprom module
 ******************************************************************************
 *  Copyright (C) by Shanghai ChipON Micro-Electronic Co.,Ltd
 *  All rights reserved.
 *
 *  This software is copyright protected and proprietary to
 *  Shanghai ChipON Micro-Electronic Co.,Ltd.
 *****************************************************************************/
/******************************************************************************
 *  |Date        |Version  |Author       |Description
 ******************************************************************************
 *  |2023-12-23  |V2.0     |Wang Junxiong|New creat
 *****************************************************************************/

#ifndef KF8A100FXX_EEPROM_H
#define KF8A100FXX_EEPROM_H

#ifdef __cplusplus
extern "C" {
#endif

/******************************************************************************
 *                      Include Files
 *****************************************************************************/
#include "kf8a100fxx.h"
/******************************************************************************
 *                      Macro or Inline
 *****************************************************************************/

/******************************************************************************
 *                      Typedef Definitions
 *****************************************************************************/

typedef enum
{
    EEPROM_CMD_SUCCESS   = 0x00u,
    EEPROM_CMD_ERROR     = 0xAAu,
    EEPROM_TIMEOUT_ERROR = 0x0Cu
} Eeprom_CmdType;
/******************************************************************************
 *                      Export Variables
 *****************************************************************************/

/* Eeprom self-write-read key: Eeprom_Key_ONE = 0x69, Eeprom_Key_TWO = 0x96 */
extern volatile uint8_t Eeprom_Key_ONE, Eeprom_Key_TWO;

/******************************************************************************
 *                      Export Functions
 *****************************************************************************/

/**
 * @brief Data eeprom reads out a single byte of data at a specified address
 * Interrupts are turned off during reads and writes
 *
 * @param Addr eeprom addr: 00H~FFH
 * @return uint8_t eeprom data
 */
uint8_t DataEeprom_SingleDate_Read(uint8_t Addr);

/**
 * @brief Data eeprom writes single-byte data to a specified address
 * Interrupts are turned off during reads and writes
 *
 * @attention 1. Write the KEY before calling the function, and clear the KEY after the function call.
 *
 * @param Addr eeprom addr: 00H~FFH
 * @param Value eeprom data
 * @return Write eeprom status
 */
Eeprom_CmdType DataEeprom_SingleData_Write(uint8_t Addr, uint8_t Value);

/**
 * @brief Data eeprom Read multibyte data at specified address
 * If address addr+len exceeds FFH, the backward data will be written from 00H.
 *
 * @attention This function cannot be called within an interrupt service routine.
 *
 * @param Addr eeprom addr: 00H~FFH
 * @param Data uint8_t eeprom data
 * @param Len uint8_t eeprom data length: 1~128
 */
void DataEeprom_MultiDate_Read(uint8_t Addr, uint8_t *Data, uint8_t Len);

/**
 * @brief Data eeprom writes multibyte data to a specified address
 * If address addr+len exceeds FFH, the backward data will be read from 00H.
 *
 * @attention 1. This function cannot be called within an interrupt service routine.
 * 2. Write the KEY before calling the function, and clear the KEY after the function call.
 *
 * @param Addr eeprom addr: 00H~FFH
 * @param Data uint8_t eeprom data
 * @param Len uint8_t eeprom data length: 1~128
 * @return Write eeprom status
 */
Eeprom_CmdType DataEeprom_MultiData_Write(uint8_t Addr, const uint8_t *Data, uint8_t Len);
#ifdef __cplusplus
}
#endif

#endif
/* EOF */
